/**
 * This file is part of the CAKIS project.
 * 
 * Copyright (c) 2009-2010 - Florian Arndt, Christian Kerl
 * 
 * @license GNU Lesser General Public License v3 <http://www.opensource.org/licenses/lgpl-3.0.html>
 * @since   31.03.2010
 * @version SVN: $Id: StockUnitRepositoryImpl.java 90 2010-04-27 11:51:46Z christian-kerl@web.de $
 */
package org.cakis.server.model.repository.impl;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.Query;

import org.cakis.server.Names;
import org.cakis.server.model.StockUnit;
import org.cakis.server.model.repository.StockUnitRepository;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;

/**
 * StockUnitRepositoryImpl
 *
 * @author Christian Kerl
 */
@Name(Names.StockUnitRepository)
@AutoCreate
@Stateless(name=Names.StockUnitRepository)
public class StockUnitRepositoryImpl extends AbstractRepository<StockUnit> implements StockUnitRepository {
    private static final long serialVersionUID = 1L;

    @Override
    protected Long getId(StockUnit object) {
        return object.getId();
    }

    @Override
    public List<StockUnit> findByNameOrSymbol(String nameOrSymbol) {
        Query q = em.createQuery("select s from StockUnit s where lower(s.name) = :value or lower(s.symbol) = :value");
        q.setParameter("value", nameOrSymbol.toLowerCase());

        return list(q);
    }

}
